import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class CardList {
    private static final String[] SUIT = {"♦","♥","♠","♣"};
    public static List<Card> buyCards(){
        List<Card> list = new ArrayList<>();
        for(int i = 0; i<SUIT.length;i++){
            for (int j = 1; j <= 13; j++) {
                /*String suit = SUIT[i];
                int rank = j;*/
                Card card = new Card(SUIT[i],j);
                list.add(card);
            }
        }
        return list;
    }
    public static void shuffle(List<Card> list){//洗牌操作
        Random random = new Random();
        for (int i = list.size() - 1; i > 0 ; i--) {
            int index = random.nextInt(i);//获得[0,i)的随机数
            swap(list,i,index);
        }
    }
    public static void swap(List<Card> list, int i,int j){//交换操作
        Card tmp = list.get(i);
        list.set(i,list.get(j));
        list.set(j,tmp);
    }

    public static void main(String[] args) {
        List<Card> list = buyCards();
        System.out.println(list);
        shuffle(list);
        System.out.println(list);
        List<List<Card>> cards = new ArrayList<>();
        List<Card> cards1 = new ArrayList<>();
        List<Card> cards2 = new ArrayList<>();
        List<Card> cards3 = new ArrayList<>();
        cards.add(cards1);
        cards.add(cards2);
        cards.add(cards3);
        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 3; j++) {
                Card card = list.remove(0);
                cards.get(j).add(card);
            }
        }
        System.out.println(cards1);
        System.out.println(cards2);
        System.out.println(cards3);
    }

}
